#!/usr/bin/env python
#
# Copyright 2009 Allen Hutchison (allen@hutchison.org)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# $URL$
__version__ = "$Rev$"
__author__ = "Allen Hutchison (allen@hutchison.org)"

import datetime
import logging
import time

from lib.status_value import CompactStatusValue
from lib.status_value import StatusValue

from google.appengine.ext import db

class DataCompactor(object):
  """Grab the oldest X items in the StatusValue table and convert them into
  CompactStatusValue objects."""
  def __init__(self, date, line):
    #date = time.strptime(date, "%Y-%m-%d")
    #self.day1 = datetime.date(date[0], date[1], date[2])
    #self.day2 = self.day1 + datetime.timedelta(days=1)
    #self.line = line
    logging.info("INIT is done %s %s %s" % (self.line, self.day2, self.day1))
    #self.getEntries()
  
  def getEntries(self):
    query = StatusValue.gql("WHERE name = :1 AND update < :2 AND update >= :3 " +
                            "ORDER BY update ASC",
                            self.line, self.day2, self.day1)
    logging.info("Query items %s" % query.count())
    for x in query:
      logging.info("query item " + x.status)
